home *** CD-ROM | disk | FTP | other *** search
- //***********************************************************************
- //
- // CtlDemo2.cpp
- //
- //***********************************************************************
-
- #include <afxwin.h>
- #include "CtlDemo2.h"
-
- #define IDC_STDEDIT 100
- #define IDC_NUMEDIT 101
-
- CMyApp myApp;
-
- /////////////////////////////////////////////////////////////////////////
- // CMyApp member functions
-
- BOOL CMyApp::InitInstance ()
- {
- m_pMainWnd = new CMainWindow;
- m_pMainWnd->ShowWindow (m_nCmdShow);
- m_pMainWnd->UpdateWindow ();
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////
- // CMainWindow message map and member functions
-
- BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
- ON_WM_CREATE ()
- END_MESSAGE_MAP ()
-
- CMainWindow::CMainWindow ()
- {
- CString strWndClass = AfxRegisterWndClass (
- 0,
- myApp.LoadStandardCursor (IDC_ARROW),
- (HBRUSH) (COLOR_3DFACE + 1),
- myApp.LoadStandardIcon (IDI_APPLICATION)
- );
-
- Create (strWndClass, "CtlDemo2");
- }
-
- int CMainWindow::OnCreate (LPCREATESTRUCT lpcs)
- {
- if (CFrameWnd::OnCreate (lpcs) == -1)
- return -1;
-
- CClientDC dc (this);
- int nHeight = -((dc.GetDeviceCaps (LOGPIXELSY) * 8) / 72);
-
- m_font.CreateFont (nHeight, 0, 0, 0, FW_NORMAL, 0, 0, 0,
- DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
- DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "MS Sans Serif");
-
- CFont* pOldFont = dc.SelectObject (&m_font);
- TEXTMETRIC tm;
- dc.GetTextMetrics (&tm);
- m_cxChar = tm.tmAveCharWidth;
- m_cyChar = tm.tmHeight + tm.tmExternalLeading;
- dc.SelectObject (pOldFont);
-
- int x1 = m_cxChar * 2;
- int x2 = m_cxChar * 24;
- int x3 = m_cxChar * 25;
- int x4 = m_cxChar * 50;
-
- int y1 = m_cyChar;
- int y2 = (m_cyChar * 11) / 4;
- int y3 = m_cyChar * 4;
- int y4 = (m_cyChar * 23) / 4;
- int dy = m_cyChar / 2;
-
- m_ctlLabel1.Create ("&Standard edit control", WS_CHILD | WS_VISIBLE |
- SS_LEFT, CRect (x1, y1 + dy, x2, y2), this);
-
- m_ctlStdEdit.CreateEx (WS_EX_CLIENTEDGE, "edit", NULL,
- WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL,
- x3, y1, x4 - x3, y2 - y1, m_hWnd, (HMENU) IDC_STDEDIT, NULL);
-
- m_ctlLabel2.Create ("&Numeric edit control", WS_CHILD | WS_VISIBLE |
- SS_LEFT, CRect (x1, y3 + dy, x2, y4), this);
-
- m_ctlNumEdit.CreateEx (WS_EX_CLIENTEDGE, "edit", NULL,
- WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL,
- x3, y3, x4 - x3, y4 - y3, m_hWnd, (HMENU) IDC_NUMEDIT, NULL);
-
- m_ctlLabel1.SetFont (&m_font, FALSE);
- m_ctlLabel2.SetFont (&m_font, FALSE);
- m_ctlStdEdit.SetFont (&m_font, FALSE);
- m_ctlNumEdit.SetFont (&m_font, FALSE);
- return 0;
- }
-
- BOOL CMainWindow::PreTranslateMessage (MSG* pMsg)
- {
- return ::IsDialogMessage (m_hWnd, pMsg);
- }
-
- /////////////////////////////////////////////////////////////////////////
- // CNumEdit message map and member functions
-
- BEGIN_MESSAGE_MAP (CNumEdit, CEdit)
- ON_WM_CHAR ()
- END_MESSAGE_MAP ()
-
- void CNumEdit::OnChar (UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- if (((nChar >= '0') && (nChar <= '9')) ||
- (nChar == VK_BACK) || (nChar == '(') || (nChar == ')') ||
- (nChar == '-') || (nChar == ' '))
-
- CEdit::OnChar (nChar, nRepCnt, nFlags);
- }
-